﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MageWars.GameElements;

namespace MageWars.Support.StateMachines.States
{
    public class Attack : State
    {
        public Attack(Mage Self)
            : base(Self)
        {

        }

        public const int Range = 100;

        public override Node[] GetCamino()
        {
            return new Node[] { };
        }

        public override MWAction GetNextAction()
        {
            Mage target = null;
            float targetDistance = Range;
            float distance;
            foreach (var m in Mage.Mages)
            {
                if (m.Group != Self.Group)
                {
                    distance = MageMath.GetDistance(m.Position, Self.Position);
                    if (distance <= targetDistance)
                    {
                        target = m;
                        targetDistance = distance;
                    }
                }
            }

            
            if (target != null)
            {
                //if (Self.HP < 30)
                //{
                //    return new MWAction() { NewState = new Flee(Self) };
                //}
                //else
                //{
                //    return new MWAction() { Fire = true, Direction = MageMath.getAngle(Self.Position, target.Position) };
                //}
                    return new MWAction() { Fire = true, Direction = MageMath.getAngle(Self.Position, target.Position) };
            }
            else
            {
                return new MWAction() { NewState = this.PreviousState };
            }
        }
    }
}
